package ex14.pyrmont.startup;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;

public class ShutDown {
	public static void main(String[] args) throws Exception {
		// Socket socket = new Socket("localhost", Server.PORT);
		//
		// // 获取输出流，用于客户端向服务器端发送数据
		// BufferedReader reader = new BufferedReader(new
		// InputStreamReader(socket.getInputStream()));
		//
		// BufferedWriter writer = new BufferedWriter(new
		// OutputStreamWriter(socket.getOutputStream()));
		//
		// writer.write("SHUTDOWN");
		//
		// String res = reader.readLine();
		// System.out.println(res);
		//
		// socket.close();

		InetAddress addr = InetAddress.getByName(null);
		System.out.println("addr = " + addr);
		Socket socket = new Socket(addr, Server.PORT);
		try {
			System.out.println("socket = " + socket);
			BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
			PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())),
					true);
			// for (int i = 0; i < 10; i++) {
			// out.println("howdy " + i);
			// String str = in.readLine();
			// System.out.println(str);
			// }
			out.println("SHUTDOWN");
		} finally {
			System.out.println("closing...");
			socket.close();
		}
	}
}
